package com.itheima.d2_byte_stream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/*
     目标：使用字节流完成对文件的复制操作。
     数据源
     目的地
 */
public class
CopyTest5 {
    public static void main(String[] args) throws Exception {
        long begin = System.currentTimeMillis();
        copy2();
        long end=System.currentTimeMillis();
        System.out.println(end-begin);
    }
    static void copy1() {
        FileInputStream fis=null;
        FileOutputStream fos=null;
        try {
            fis = new FileInputStream("F:\\视频\\N卡\\视频\\PLAYERUNKNOWN'S BATTLEGROUNDS\\PLAYERUNKNOWN'S BATTLEGROUNDS 2024.11.20 - 01.14.34.02.DVR.mp4");
            fos = new FileOutputStream("F:\\视频\\N卡\\视频\\PLAYERUNKNOWN'S BATTLEGROUNDS\\a.mp4");
            int a;
            while((a=fis.read())!=-1){
                fos.write(a);
            }
        } catch(Exception e){

        }finally {
            try {
                if(fis!=null)
                fis.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            try {
                if(fos!=null)
                fos.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    }
    static void copy2() {
        try ( FileInputStream fis=new FileInputStream("F:\\视频\\N卡\\视频\\PLAYERUNKNOWN'S BATTLEGROUNDS\\PLAYERUNKNOWN'S BATTLEGROUNDS 2024.11.20 - 01.14.34.02.DVR.mp4");
              FileOutputStream fos=new FileOutputStream("F:\\视频\\N卡\\视频\\PLAYERUNKNOWN'S BATTLEGROUNDS\\a.m4");){
//            FileInputStream fis=new FileInputStream("F:\\视频\\N卡\\视频\\PLAYERUNKNOWN'S BATTLEGROUNDS\\PLAYERUNKNOWN'S BATTLEGROUNDS 2024.11.20 - 01.14.34.02.DVR.mp4");
//            FileOutputStream fos=new FileOutputStream("F:\\视频\\N卡\\视频\\PLAYERUNKNOWN'S BATTLEGROUNDS\\a.m4");
            int a;
            byte[] bytes=new byte[1024];
            while((a=fis.read(bytes))!=-1){
                fos.write(bytes,0,a);
            }
//            fis.close();
//            fos.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}






































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































